package com.aaa.base.service.impl;

import com.aaa.base.mapper.LocatorMapper;
import com.aaa.base.service.LocatorService;
import com.aaa.entity.base.Locator;
import com.aaa.entity.stock.Stock;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aaa
 * @since 2020-11-23
 */
@Service
public class LocatorServiceImpl extends ServiceImpl<LocatorMapper, Locator> implements LocatorService {

    @Autowired
    private LocatorMapper locatorMapper;

    @Override
    public Page<Locator> searchLocator(Integer page, Integer limit, Locator locator,Long warehouseid) {
        Page<Locator> pageinfo=new Page<>(page,limit);
        String name=locator.getName();
        String code=locator.getCode();
        String type=locator.getType();
        QueryWrapper<Locator> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(name)){
            queryWrapper.like("name",name);
        }
        if(StringUtils.isNotEmpty(code)){
            queryWrapper.like("code",code);
        }
        if(StringUtils.isNotEmpty(type)){
            queryWrapper.like("type",type);
        }
        if(warehouseid!=null){
            queryWrapper.eq("warehouseid",warehouseid);
        }
        this.locatorMapper.selectPage(pageinfo, queryWrapper);
        return pageinfo;
    }

    @Override
    public List<Map> findType() {
        return locatorMapper.findType();
    }

    @Override
    public Locator selectTarLocByLoCode(String locatorcode, Long warehouseid) {
        QueryWrapper<Locator> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("code",locatorcode);
        queryWrapper.eq("warehouseid",warehouseid);
        Locator locator=locatorMapper.selectOne(queryWrapper);
        return locator;
    }

    @Override
    public List<Locator> selectLocByWareId(Long warehouseid) {
        QueryWrapper<Locator> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("warehouseid",warehouseid);
        queryWrapper.eq("state","0");
        List<Locator> locators = locatorMapper.selectList(queryWrapper);
        return locators;
    }

    @Override
    public List<Locator> selectLocByWareIdState(Long warehouseid) {
        QueryWrapper<Locator> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("warehouseid",warehouseid);
        queryWrapper.eq("state","2");
        List<Locator> locators = locatorMapper.selectList(queryWrapper);
        return locators;
    }

    @Override
    public List<Map> selectIMoLo() {
        return this.baseMapper.selectIMoLo();
    }

    @Override
    public List<Stock> selectStockByLocCode(String code) {
        return this.baseMapper.selectStockByLocCode(code);
    }
}
